// Quantitative Angiogram Analysis System
//
// Copyright ?Ping Zou, 2007
// sg71.cherub@gmail.com

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using eee.Sheffield.PZ.Imaging;
using eee.Sheffield.PZ.Imaging.ImageFilter;

namespace eee.Sheffield.PZ.QAAS
{
    /// <summary>
    /// flood fillter filter control
    /// </summary>
    public partial class FloodFillFilterControl : FilterControl//, IFilterControl
    {
        #region Fields
        //private string _flag = "Flood Fill Filter";
        #endregion

        #region Properties
        //public override string Flag { get { return _flag; } }
        #endregion

        #region Constructor
        public FloodFillFilterControl() 
        { 
            InitializeComponent(); 
            _flag = "Flood Fill Filter";
        }

        public FloodFillFilterControl(MainForm mainForm, ImageDoc imageDoc) : base(mainForm, imageDoc)
        {
            InitializeComponent();
            _flag = "Flood Fill Filter";
        } 
        #endregion

        #region interface methods
        public override void Reload() { }
        #endregion

        #region ButtonEvents
        private void buttonStart_Click(object sender, EventArgs e)
        {
            int initx = 164;
            int inity = 21;
            PZPoint startPoint = new PZPoint(initx, inity);
            Bitmap dstImage = DoFloodFill(_imageDoc.Image, startPoint, out _log);
            _mainForm.ShowImage(dstImage, "Flood Fill result");
            _mainForm.Log(_log);
        } // buttonStart_Click()

        private Bitmap DoFloodFill(Bitmap srcImage, PZPoint startPoint, out string logText)
        {
            FloodFill filter = new FloodFill();
            // flood fill condition type
            if (radioButtonThreshold.Checked)
                filter.FloodFillConditionType = FloodFillConditionType.Threshold;
            if (radioButtonTolerance.Checked)
                filter.FloodFillConditionType = FloodFillConditionType.Tolerance;
            if (radioButtonAdaptiveThreshold.Checked)
                filter.FloodFillConditionType = FloodFillConditionType.AdaptiveThreshold;
            if (radioButtonAdaptiveTolerance.Checked)
                filter.FloodFillConditionType = FloodFillConditionType.AdaptiveTolerance;
            // flood fill type
            filter.FloodFillType = FloodFillType.Iterative;
            // start point
            filter.StartPoint = startPoint;
            // stardarize srcImage to Format8bppIndexed as calling graylevel image filter
            Bitmap copySrcImage = (Bitmap)srcImage.Clone();
            eee.Sheffield.PZ.Imaging.Image.StandardizeImageTo8bbpIndexed(ref copySrcImage);
            Bitmap dstImage = filter.ApplyGraylevelImageFilter(copySrcImage);
            logText = filter.LogText;
            return dstImage;
        } // DoFloodFill()
        #endregion
    }
}
